package com.sky.controller.admin;

import com.sky.dto.SetmealDTO;
import com.sky.dto.SetmealPageQueryDTO;
import com.sky.result.Result;
import com.sky.service.SetmealService;
import com.sky.vo.SetmealVO;
import com.sky.vo.setmealPageQueryVO;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


@RestController
@RequestMapping("/admin/setmeal")
public class SetmealController {

    @Autowired
    private SetmealService setmealService;

    @PostMapping
    public Result add(@RequestBody SetmealDTO setmealDTO) {
        setmealService.add(setmealDTO);
        return Result.success();
    }

    @GetMapping("/page")
    public Result<setmealPageQueryVO> page( SetmealPageQueryDTO setmealPageQueryDTO) {
        setmealPageQueryVO data  = setmealService.page(setmealPageQueryDTO);
        return Result.success(data);
    }

    @PutMapping
    public Result update(@RequestBody SetmealDTO setmealDTO) {
        setmealService.update(setmealDTO);
        return Result.success();
    }

    @DeleteMapping
    public Result delete(String ids){
        setmealService.delete(ids);
        return Result.success();
    }

    @GetMapping("/{id}")
    public Result getById(@PathVariable String id) {
        SetmealVO result = setmealService.getById(id);
        return Result.success(result);
    }

    @PostMapping("/status/{status}")
    public Result updateStatus(@PathVariable String status,@Param("id") String id) {
        setmealService.updateStatus(status,id);
        return Result.success();
    }

}
